package com.ithuameng.admin.app.system.model.vo;

import com.ithuameng.admin.enums.BaseError;
import com.ithuameng.admin.enums.CommonError;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;

/**
 * R
 *
 * @author ithuameng
 */
@ApiModel("接口返回数据")
public class R<T> implements Serializable {

    private static final long serialVersionUID = -7469293891184155973L;

    /**
     * 请求是否完成
     */
    @ApiModelProperty("请求是否完成")
    private boolean result;

    /**
     * 业务错误码
     */
    @ApiModelProperty("错误代码")
    private long code;

    /**
     * 结果集
     */
    @ApiModelProperty("接口返回数据")
    private T data;

    /**
     * 描述
     */
    @ApiModelProperty("描述")
    private String message;

    public R() {
        // to do nothing
    }

    public R(BaseError baseError) {
        this.code = baseError.getValue();
        this.message = baseError.getDesc();
    }

    public R(BaseError baseError, String msg) {
        this.code = baseError.getValue();
        this.message = msg;
    }

    public R(T data) {
        this.data = data;
        this.code = CommonError.OK.getValue();
    }

    public boolean isResult() {
        return 200L == code;
    }

    public long getCode() {
        return code;
    }

    public void setCode(long code) {
        this.code = code;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}
